package cn.itcast.xml.jsoup;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

/**
 * Element 对象功能
 */
public class JsoupDemo4 {
    public static void main(String[] args) throws IOException {
        // 1.获取 student.xml 文件路径
        String path = JsoupDemo4.class.getClassLoader().getResource("student.xml").getPath();
        // 2.获取 document 对象
        Document document = Jsoup.parse(new File(path), "utf-8");

        // 通过 Document 对象获取所有的 name 标签的对象
        Elements elements = document.getElementsByTag("name");
        System.out.println(elements);
        System.out.println("---------");
        
        // 通过 Element 对象获取子标签对象
        Element ele_student = document.getElementsByTag("student").get(0);
        Elements ele_name = ele_student.getElementsByTag("name");
        System.out.println(ele_name.size());
        System.out.println("---------");

        // 获取 student 对象的属性值
        String number = ele_student.attr("number");
        System.out.println(number);
        System.out.println("---------");

        // 获取文本内容
        String text = ele_name.text();
        String html = ele_name.html();
        System.out.println(text);
        System.out.println(html);


    }
}
